#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

int same_file(struct stat *stat1,struct stat *stat2)
{
  return stat1 -> st_ino = stat2 -> st_ino
    && stat1 -> st_dev == stat2 -> st_dev  ;
}

int name_too_long(char *name,struct stat *statb)
{
  int s = strlen(name);
  char c = name[s - 1];
  struct stat tstat;
  int res;

  tstat = *statb;
  name[s - 1] = '\0';
  res = stat(name,&tstat) == 0&&same_file(statb,&tstat);
  name[s - 1] = c;
  return res;
}


int main(int argc,char **argv)
{
  struct stat stat_file1;
  struct stat stat_file2;
  char *name = (char *)malloc(16*sizeof(char));
  name = "name_too_long.c";
  int res = stat(name,&stat_file1);
  int tmp = name_too_long(name,&stat_file1);
  printf("res = %d\n",res);
  printf("tmp = %d\n",tmp);
  return 0;
}
